package com.yulinlin.admin.modules.generate.domain;

import com.yulinlin.jdbc.model.AbstractQueryModel;
import com.yulinlin.jdbc.model.anno.JoinField;
import com.yulinlin.jdbc.model.anno.JoinTable;
import com.yulinlin.jdbc.model.anno.JoinWhere;
import com.yulinlin.lang.util.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@JoinTable("information_schema.tables")
public class TableInfo extends AbstractQueryModel<TableInfo> {

    @ApiModelProperty("数据库")
    @JoinWhere
    @JoinField
    private String tableSchema;

    @ApiModelProperty("表明")
    @JoinWhere
    @JoinField
    private String tableName;

    @ApiModelProperty("表注释")
    @JoinWhere
    @JoinField
    private String tableComment;

    private List<ColumnInfo> columnList;

    public List<ColumnInfo> getColumnList(){
        if(columnList != null){
            return  columnList;
        }
        ColumnInfo columnInfo = new ColumnInfo();
        columnInfo.setTableName(tableName);
        columnInfo.setTableSchema(tableSchema);
        columnList =  columnInfo.createSelectWrapper().selectList();
        return  columnList;
    }

    public String getClassName(){
        return StringUtil.tableToClass(tableName);
    }

}
